﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WinFormsApp1.Common;

namespace WinFormsApp1.WangHaoQi._02Winfroms
{
    public partial class OilyfatAdd : Form
    {
        public OilyfatAdd()
        {
            InitializeComponent();
            GetDepot();
            GetUPCData();
        }

        //仓库
        public async void GetDepot()
        {
            var items = await HttpClientHelper.RequestUrl<string, ApiResult<List<Depotes>>>(URLCommon.Url2, "/Tsw/GetDepottypeData", HttpClientHelper.MethodType.GET, default);

            uiComboBox1.DataSource = items.Data;
            uiComboBox1.DisplayMember = "DepotTypeName";
            uiComboBox1.ValueMember = "DepotTypeId";

            this.Controls.Add(uiComboBox1);
        }

        public class Depotes
        {
            public int DepotTypeId { get; set; }
            public string DepotTypeName { get; set; }
        }

        //商品代号
        public async void GetUPCData()
        {
            var items = await HttpClientHelper.RequestUrl<string, ApiResult<List<UPCDataser>>>(URLCommon.Url2, "/WeekListOne_Leo/GetUPCDataShow", HttpClientHelper.MethodType.GET, default);

            uiComboBox2.DataSource = items.Data;
            uiComboBox2.DisplayMember = "UPCDataName";
            uiComboBox2.ValueMember = "GoodsMinuteId";

            this.Controls.Add(uiComboBox2);
        }

        public class UPCDataser
        {
            public int GoodsMinuteId { get; set; }
            public string UPCDataName { get; set; }
        }

        public record Oilyfatert(int DepotTypeId, string OilyfatPlanNum, DateTime OilyfatTime, int GoodsMinuteId, string OilyfatNum, string OilyfatGrossWeight,
           string OilyfatTares, string OilyfatWeight, string OilyfatRemark, bool IsDelete);

        //保存
        private async void uiButton1_Click(object sender, EventArgs e)
        {
            var DepotTypeId = Convert.ToInt32(uiComboBox1.SelectedValue);
            var OilyfatPlanNum = uiTextBox1.Text;
            var OilyfatTime =Convert.ToDateTime( uiDatetimePicker1.Text);
            var GoodsMinuteId= Convert.ToInt32(uiComboBox2.SelectedValue);
            var OilyfatNum = uiTextBox2.Text;
            var OilyfatGrossWeight = uiTextBox3.Text;
            var OilyfatTares = uiTextBox4.Text;
            var OilyfatWeight = uiTextBox5.Text;
            var OilyfatRemark = uiTextBox6.Text;
            var IsDelete = false;



            Oilyfatert clients = new(DepotTypeId, OilyfatPlanNum, OilyfatTime, GoodsMinuteId, OilyfatNum, OilyfatGrossWeight, OilyfatTares, OilyfatWeight, OilyfatRemark, IsDelete);
            var res = await HttpClientHelper.RequestUrl<Oilyfatert, ApiResult<Oilyfats>>(URLCommon.Url1, "/WorkList01_leo/GetOilyfatAdd", HttpClientHelper.MethodType.POST, clients);
            if (res.Code == 1)
            {
                MessageBox.Show("添加成功");
            }
        }

        public class Oilyfats
        {
            /// <summary>
            /// 膘油称重
            /// </summary>
            public int OilyfatId { get; set; }
            /// <summary>
            /// 仓库
            /// </summary>
            public int DepotTypeId { get; set; }

            /// <summary>
            /// 计划号
            /// </summary>
            public string OilyfatPlanNum { get; set; }

            /// <summary>
            /// 称重时间
            /// </summary>
            public DateTime OilyfatTime { get; set; }

            /// <summary>
            /// 商品代号
            /// </summary>
            public int GoodsMinuteId { get; set; }

            /// <summary>
            /// 件数
            /// </summary>
            public string OilyfatNum { get; set; }
            /// <summary>
            /// 毛重
            /// </summary>
            public string OilyfatGrossWeight { get; set; }

            /// <summary>
            /// 皮重
            /// </summary>
            public string OilyfatTares { get; set; }

            /// <summary>
            /// 净重
            /// </summary>
            public string OilyfatWeight { get; set; }


            /// <summary>
            /// 备注
            /// </summary>
            public string OilyfatRemark { get; set; }

            /// <summary>
            /// 是否删除
            /// </summary>
            public bool IsDelete { get; set; }
        }
    }
}
